/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mygameframework.isoengine;

import java.awt.Point;

/**
 *
 * @author bill
 */
public class TileWalker {
    private MapType mapType;

    public TileWalker() {
        mapType= MapType.MAP_RECTANGULAR;
    }
    protected Point sileTileWalk(Point ptStart,Direction dir){
        Point tmp=new Point(ptStart);
        switch (dir) {
            case NORTH:
                tmp.x++;
                tmp.y-=2;
                break;
            case NORTHEAST:
                tmp.x++;
                tmp.y--;
                break;
            case EAST:
                tmp.x++;
                break;
            case SOUTHEAST:
                tmp.y++;
                break;
            case SOUTH:
                tmp.x--;
                tmp.y+=2;
                break;
            case SOUTHWEST:
                tmp.x--;
                tmp.y++;
                break;
            case WEST:
                tmp.x--;
                break;
            case NORTHWEST:
                tmp.y--;
                break;
            default:
                throw new AssertionError();
        }
        return tmp;
    }
    protected Point staggeredTileWalk(Point ptStart,Direction dir){
        Point tmp=new Point(ptStart);
        switch (dir) {
            case NORTH:
                tmp.y-=2;
                break;
            case NORTHEAST:
                tmp.x+=(ptStart.y&1);
                tmp.y--;
                break;
            case EAST:
                tmp.x++;
                break;
            case SOUTHEAST:
                tmp.y++;
                tmp.x+=(ptStart.y&1);
                break;
            case SOUTH:
                tmp.y+=2;
                break;
            case SOUTHWEST:
                tmp.x+=((ptStart.y&1)-1);
                tmp.y++;
                break;
            case WEST:
                tmp.x--;
                break;
            case NORTHWEST:
                tmp.y--;
                tmp.x+=((ptStart.y&1)-1);
                break;
            default:
                throw new AssertionError();
        }
        return tmp;
    }
    protected Point diamondTileWalk(Point ptStart,Direction dir){
        Point tmp=new Point(ptStart);
        switch (dir) {
            case NORTH:
                tmp.x--;
                tmp.y--;
                break;
            case NORTHEAST:
                tmp.y--;
                break;
            case EAST:
                tmp.x++;
                tmp.y--;
                break;
            case SOUTHEAST:
                tmp.x++;
                break;
            case SOUTH:
                tmp.x++;
                tmp.y++;
                break;
            case SOUTHWEST:
                tmp.y++;
                break;
            case WEST:
                tmp.x--;
                tmp.y++;
                break;
            case NORTHWEST:
                tmp.x--;
                break;
            default:
                throw new AssertionError();
        }
        return tmp;
    }
    protected Point rectangleTileWalk(Point ptStart,Direction dir){
        Point tmp=new Point(ptStart);
        switch (dir) {
            case NORTH:
                tmp.y--;
                break;
            case NORTHEAST:
                tmp.x++;
                tmp.y--;
                break;
            case EAST:
                tmp.x++;
                break;
            case SOUTHEAST:
                tmp.y++;
                tmp.x++;
                break;
            case SOUTH:
                tmp.y++;
                break;
            case SOUTHWEST:
                tmp.x--;
                tmp.y++;
                break;
            case WEST:
                tmp.x--;
                break;
            case NORTHWEST:
                tmp.y--;
                tmp.x--;
                break;
            default:
                throw new AssertionError();
        }
        return tmp;
    }
    public Point tileWalk(Point ptStart,Direction dir){
        Point result;
        switch (mapType) {
            case MAP_SLIDE:
                result=sileTileWalk(ptStart,dir);
                break;
            case MAP_STAGGERED:
                result=staggeredTileWalk(ptStart,dir);
                break;
            case MAP_DIAMOND:
                result=diamondTileWalk(ptStart,dir);
                break;
            case MAP_RECTANGULAR:
                result=rectangleTileWalk(ptStart,dir);
                break;
            default:
                throw new AssertionError();
        }
        return result;
    }

    public MapType getMapType() {
        return mapType;
    }

    public void setMapType(MapType mapType) {
        this.mapType = mapType;
    }
    
}
